package com.example.havi.util;

import com.hyphenate.EMCallBack;
import com.hyphenate.EMValueCallBack;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMGroup;
import com.hyphenate.chat.EMGroupManager;
import com.hyphenate.chat.EMGroupOptions;

/**
 * 封装环信 sdk 的方法
 */
public class ApiUtil {

    /**
     * 创建群组
     * @param groupName
     * @param desc
     * @param allMembers
     * @param image
     */
    public static void asyncCreateGroup(String groupName,String desc,String[] allMembers,String image){
        EMGroupOptions option = new EMGroupOptions();
        option.maxUsers = 200;
        option.style = EMGroupManager.EMGroupStyle.EMGroupStylePublicOpenJoin;  //这里类型可选
        EMClient.getInstance().groupManager().asyncCreateGroup(groupName, desc, allMembers, image, option, new EMValueCallBack<EMGroup>() {
            @Override
            public void onSuccess(EMGroup emGroup) {
                String groupId = emGroup.getGroupId();

            }

            @Override
            public void onError(int i, String s) {
                LogUtil.e("frank", "创建群聊失败：" + s);
            }
        });

    }

    /**
     * 解散群 只有创建者才可以解散
     * @param groupId
     */
    public static void asyncDestroyGroup(String groupId){
        EMClient.getInstance().groupManager().asyncDestroyGroup(groupId, new EMCallBack() {
            @Override
            public void onSuccess() {
                LogUtil.e("frank", " 解散群");
            }

            @Override
            public void onError(int i, String s) {
                LogUtil.e("frank", " 解散群失败" + s);
            }

            @Override
            public void onProgress(int i, String s) {

            }
        });

    }
}
